
ARG ROS_DISTRO=foxy
# ===============================================================
FROM registry.cn-hangzhou.aliyuncs.com/mach_image/ros:foxy-desktop as base

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo 'Asia/Shanghai' >/etc/timezone

RUN --mount=type=bind,target=apt_mirror.sh,source=scripts/apt_mirror.sh \
    . apt_mirror.sh && \
    apt-get update && \
    apt-get install -y --no-install-recommends \
    curl \
    vim \
    zsh \
    openssh-client \
    sshpass \
    python3-pip \
    python3-tk \
    psmisc \
    "ros-$ROS_DISTRO-mcap-vendor" \
    "ros-$ROS_DISTRO-rmw-cyclonedds-cpp"; \
    if [ $ROS_DISTRO == "foxy" ]; then \
    apt-get install -y --no-install-recommends autoconf pkgconf git-lfs git  curl wget openssh*  vim make build-essential gfortran file ros-$ROS_DISTRO-rosbag2-storage-mcap; \
    fi; \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /mnt/mach/work

FROM base as python_env
ARG DEBIAN_FRONTEND=noninteractive
RUN \
  apt-get install -y python3-pip &&\
  python3 -m pip install --upgrade pip &&\
  python3 -m pip install --no-cache-dir -U \
  testresources \
  pyquaternion \
  scipy \
  "conan<2" \
  cmake==3.23.3 \
  setuptools \
  numpy \
  transforms3d \
  lark-parser \
  cantools \
  toml \
  catkin_pkg \
  setuptools==58.2.0 \
  empy==3.3.2 &&\
  python3 -m pip uninstall quaternion &&\
  python3 -m pip install --upgrade --no-deps --force-reinstall numpy-quaternion
# 添加环境变量到.bashrc文件
RUN echo 'source /opt/ros/$ROS_DISTRO/setup.bash' >> ~/.bashrc
RUN echo 'export PATH=/opt/ros/$ROS_DISTRO/bin:$PATH' >> ~/.bashrc

FROM python_env as conan_env
ARG DEBIAN_FRONTEND=noninteractive
RUN \
  conan profile new default --detect &&\
  conan profile update settings.compiler.libcxx=libstdc++11 default &&\
  conan config set general.revisions_enabled=1 &&\
  echo tools.system.package_manager:mode = install >>~/.conan/global.conf &&\
  echo tools.system.package_manager:sudo = True >>~/.conan/global.conf &&\
  conan remote add std https://std-conan-jfrog-transformer.mcd.megvii-inc.com/artifactory/api/conan/std --insert &&\
  conan remote add mcd https://conan-jfrog-transformer-conan.mcd.megvii-inc.com/artifactory/api/conan/conan --insert &&\
  sed -i 's#path = .*#path = /share/conan/data#' /root/.conan/conan.conf


